package com.dhj.jvmstudy.chapter11;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * 指令8 异常处理
 */
public class ExceptionTest {

    public void thorwZero(int i){
        if(i == 0){
            throw new RuntimeException("参数值为0");
        }
    }

    public void thorwOne(int i) throws RuntimeException {
        if(i == 1){
            throw new RuntimeException("参数值为1");
        }
    }

    public void throwArithmetic(){
        int i=10;
        int j = i / 0;
        System.out.println("hello");
    }

    public void thrCatch(){
        try {
            File file = new File("d:/hello.txt");
            FileInputStream fis = new FileInputStream(file);
            String info = "hello";
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (RuntimeException e2){
            e2.printStackTrace();
        }
    }

    // 思考，如下方法返回结果为多少
    public static String func(){
        String str = "hello";
        try {
            return str;
        }finally {
            str = "dahuajia";
            System.out.println("---");
        }
    }

    public static void main(String[] args) {
        System.out.println(func());
    }

}
